package indi.service;

import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;

import indi.Data.BorrowBookLiscence;
import indi.Data.RecordOfBorrow;

public class RecordManager {

	//当前记录个数
	static int COUNTOFRECORD;
	//当前借书记录
	private ArrayList<RecordOfBorrow> currentRecords;
	
	//构造函数
	public RecordManager() {
		super();
		this.COUNTOFRECORD = 0;
		this.currentRecords = new ArrayList<>();
		
	}
	
	//添加借书记录;返回生成的借阅记录
	public RecordOfBorrow addBorrowRecord(BorrowBookLiscence liscence, String isbn, Date date) {
		RecordOfBorrow record = null;
		try {
			//生成一条借书记录，通过isbn和liscence添加联系
			record = new RecordOfBorrow(liscence, isbn, date);
			//将借书记录添加到列表
			currentRecords.add(record);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return record;
	}
	
	//删除借书记录
	public boolean deleteBorrowRecord(String isbn) {
		for(int i =0; i<currentRecords.size();i++) {
			//第i本书的isbn equals，则删掉
			if(true == currentRecords.get(i).getCurrentBookIsbn().equals(isbn)) {
				currentRecords.remove(i);
				return true;
			}
		}
		return false;
	}
	//更新借书记录
	public boolean updateBorrowRecord(String isbn) {
		return false;
	}
	//查询借书记录
	public RecordOfBorrow queryBorrowRecord(String isbn) {
		
		try {
			for(RecordOfBorrow e:currentRecords) {
				if(isbn.equals(e.getCurrentBookIsbn())) {
					return e;
				}
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
			
		return null;
	}
	//判断一条借书记录是否逾期
	public boolean isOverdue(RecordOfBorrow record) {
		return false;
	}
	//返回借书记录个数
	public static int getCOUNTOFRECORD() {
		return COUNTOFRECORD;
	}
}
